package com.shuigu.controller;

import com.shuigu.response.ShuiGuResult;
import com.shuigu.utils.QCloudUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
public class UploadController {

    @Resource(name = "QCloudUtils")
    private QCloudUtils qCloudUtils;

    @PostMapping("/upload")
    public ShuiGuResult upload(@RequestParam("file") MultipartFile image) throws IOException {

        log.info("上传文件名: {}", image.getOriginalFilename());
        String url = qCloudUtils.createUpload(image);
        log.info("文件上传完成访问的url: {}", url);
        return ShuiGuResult.success(url);
    }
}
